package ar.edu.itba.it.cg.grupo01.impl;

import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

public class CameraBuilder {

	private Camera resultCamera = null;
	private Point3f origin;
	private Vector3f viewingDirection;
	private Vector3f upVector;
	private int xResolution = Integer.MIN_VALUE;
	private int yResolution = Integer.MIN_VALUE;
	private float fov = Float.MIN_VALUE;

	public Camera getResultCamera() {
		return resultCamera;
	}

	public void setResultCamera(Camera resultCamera) {
		this.resultCamera = resultCamera;
	}

	public Point3f getOrigin() {
		return origin;
	}

	public void setOrigin(Point3f origin) {
		this.origin = origin;
	}

	public Vector3f getViewingDirection() {
		return viewingDirection;
	}

	public void setViewingDirection(Vector3f viewingDirection) {
		this.viewingDirection = viewingDirection;
		if(this.viewingDirection != null)
			this.viewingDirection.normalize();
	}

	public Vector3f getUpVector() {
		return upVector;
	}

	public void setUpVector(Vector3f upVector) {
		this.upVector = upVector;
		if(this.upVector != null)
			this.upVector.normalize();
	}

	public int getxResolution() {
		return xResolution;
	}

	public void setxResolution(int xResolution) {
		this.xResolution = xResolution;
	}

	public int getyResolution() {
		return yResolution;
	}

	public void setyResolution(int yResolution) {
		this.yResolution = yResolution;
	}

	public float getFov() {
		return fov;
	}

	public void setFov(float fov) {
		this.fov = fov;
	}

	public Camera build() {
		if (constructionIsNotReady())
			throw new IllegalStateException("CameraBuilder not ready");

		resultCamera = new Camera(origin, viewingDirection, upVector,
				xResolution, yResolution, fov);

		return resultCamera;
	}

	private boolean constructionIsNotReady() {
		return (origin == null || viewingDirection == null || upVector == null
				|| xResolution == Integer.MIN_VALUE
				|| yResolution == Integer.MIN_VALUE || fov == Double.MIN_VALUE);
	}

}
